package com.ksd.modules.search.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ksd.common.annotation.ApiLog;
import com.ksd.common.controller.BaseController;
import com.ksd.common.core.result.R;
import com.ksd.common.po.BatchIdsPO;
import com.ksd.common.web.annotation.RepeatSubmit;
import com.ksd.modules.search.po.SearchKeywordsSavePO;
import com.ksd.modules.search.po.SearchKeywordsSearchPO;
import com.ksd.modules.search.service.ISearchKeywordsService;
import com.ksd.modules.search.vo.SearchKeywordsVo;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
public class SearchKeywordsController extends BaseController {
    
    @Autowired
    private ISearchKeywordsService searchKeywordsService;

    /**
     * 【搜索关键词】- 列表
     * @return
     */
    @PostMapping("/searchkeywords/list")
    public R<Page<SearchKeywordsVo>> findSearchKeywordss(@Validated @RequestBody SearchKeywordsSearchPO searchKeywordsSearchPO){
        return R.data(searchKeywordsService.findSearchKeywordss(searchKeywordsSearchPO));
    }

    /**
     * 【搜索关键词】- 回收站
     * @return
     */
    @PostMapping("/searchkeywords/recyle")
    public R<Page<SearchKeywordsVo>> findSearchKeywordssRecyle(@Validated @RequestBody SearchKeywordsSearchPO searchKeywordsSearchPO){
        return R.data(searchKeywordsService.findSearchKeywordssRecyle(searchKeywordsSearchPO));
    }

    /**
     * 【搜索关键词】 - 保存和更新
     * @param searchKeywordsSavePO
     * @return
     */
    @PostMapping("/searchkeywords/saveupdate")
    @ApiLog("【搜索关键词】 - 保存和更新")
    @RepeatSubmit
    public R<SearchKeywordsVo> saveUpdateSearchKeywords(@Validated @RequestBody SearchKeywordsSavePO searchKeywordsSavePO){
        return R.data(searchKeywordsService.saveUpdateSearchKeywords(searchKeywordsSavePO));
    }

    /**
     * 【搜索关键词】 - 根据id查询明细
     * @param id
     * @return
     */
    @PostMapping("/searchkeywords/get/{id}")
    public R<SearchKeywordsVo> getSearchKeywordsById(@PathVariable("id")Long id){
        return R.data(searchKeywordsService.getSearchKeywordsById(id));
    }

    /**
     * 【搜索关键词】 - 根据id删除搜索关键词
     * @param id
     * @return
     */
    @PostMapping("/searchkeywords/del/{id}")
    @ApiLog("【搜索关键词】 - 根据id删除搜索关键词 ")
    public R<Boolean> deleteSearchKeywordsById(@PathVariable("id")Long id){
        return R.data(searchKeywordsService.deleteSearchKeywordsById(id));
    }

    /**
     * 【搜索关键词】- 根据id恢复删除
     *
     * @param id
     * @return
     */
    @PostMapping("/searchkeywords/recover/{id}")
    @ApiLog("【搜索关键词】- 根据id恢复删除")
    @RepeatSubmit
    public R<Boolean> recoverByIdSearchKeywords(@PathVariable("id") Long id) {
        return R.data(searchKeywordsService.recoverByIdSearchKeywords(id));
    }

    /**
     * 【搜索关键词】- 批量逻辑删除
     *
     * @return
     */
    @PostMapping("/searchkeywords/batch/dels")
    @ApiLog("【搜索关键词】- 批量逻辑删除")
    @RepeatSubmit
    public R<Boolean> bacthDeletesSearchKeywords(@RequestBody BatchIdsPO batchIdsPO) {
        return R.data(searchKeywordsService.bacthDeletesSearchKeywords(batchIdsPO));
    }


    /**
     * 【搜索关键词】- 批量恢复
     *
     * @return
     */
    @PostMapping("/searchkeywords/batch/recover")
    @ApiLog("【搜索关键词】- 批量恢复")
    @RepeatSubmit
    public R<Boolean> batchRecoversSearchKeywords(@RequestBody BatchIdsPO batchIdsPO) {
        return R.data(searchKeywordsService.batchRecoversSearchKeywords(batchIdsPO));
    }
    
    /**
     * 【搜索关键词】- 批量物理删除
     *
     * @return
     */
    @PostMapping("/searchkeywords/batch/remove")
    @ApiLog("【搜索关键词】- 批量物理删除")
    @RepeatSubmit
    public R<Boolean> batchRemovesSearchKeywords(@RequestBody BatchIdsPO batchIdsPO) {
        return R.data(searchKeywordsService.batchRemovesSearchKeywords(batchIdsPO));
    }

    /**
     * 【搜索关键词】- 根据ID恢复删除
     * @param id
     * @return
     */
    @PostMapping("/searchkeywords/remove/{id}")
    @ApiLog("【搜索关键词】- 根据ID恢复删除")
    public R<Boolean> removeSearchKeywordsById(@PathVariable("id")Long id){
        return R.data(searchKeywordsService.removeSearchKeywordsById(id));
    }

    /**
     * 【搜索关键词】- 修改状态
     *
     * @return
     */
    @PostMapping("/searchkeywords/status/{id}/{field}")
    @ApiLog("【搜索关键词】- 修改状态")
    @RepeatSubmit
    public R<Boolean> updateStatus(
            @PathVariable("id") Long id,
            @PathVariable("field") String field,
            @RequestParam("value") String value
    ) {
        if(StringUtils.isNumeric(value)) {
            return R.data(searchKeywordsService.updateStatus(id, field, Integer.parseInt(value)));
        }else{
            return R.data(searchKeywordsService.updateStatusStr(id, field, String.valueOf(value)));
        }
    }

    /**
     * 【搜索关键词】-批量上架
     *
     * @return
     */
    @PostMapping("/searchkeywords/batch/up")
    @ApiLog("批量上架")
    @RepeatSubmit
    @ApiOperation("【搜索关键词】-批量上架")
    public R<Boolean> batchUps(@RequestBody BatchIdsPO batchIdsPO) {
        return R.data(searchKeywordsService.batchUps(batchIdsPO));
    }

    /**
     * 【搜索关键词】-批量下架
     *
     * @return
     */
    @PostMapping("/searchkeywords/batch/down")
    @ApiLog("【搜索关键词】-批量下架")
    @RepeatSubmit
    public R<Boolean> batchDowns(@RequestBody BatchIdsPO batchIdsPO) {
        return R.data(searchKeywordsService.batchDowns(batchIdsPO));
    }
}
